package com.hzlj.position.locate.dao;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fz.common.base.converter.QueryWrapperConverterPlus;
import com.fz.common.base.dto.PageParamDTO;
import com.fz.common.base.dto.QueryPageResultDTO;
import com.hzlj.position.locate.common.dto.abnGatheringJzry.AbnGatheringJzryPositionIdDTO;
import com.hzlj.position.locate.common.dto.abnGatheringJzry.AbnGatheringJzryQueryParamDTO;
import com.hzlj.position.locate.common.dto.abnGatheringJzry.AbnGatheringJzryQueryResultDTO;
import com.hzlj.position.locate.common.model.AbnGatheringJzry;
import com.hzlj.position.locate.mapper.AbnGatheringJzryMapper;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * 定位分析-聚众告警表-定位信息(AbnGatheringJzry)表操作类
 *
 * @author lifh
 * @date 2023-03-28 10:20:24
 */
@Repository
public class AbnGatheringJzryDao extends ServiceImpl<AbnGatheringJzryMapper, AbnGatheringJzry> {
    @Resource
    private AbnGatheringJzryMapper abnGatheringJzryMapper;


    public List<String> existsPositionIds(String gatheringId, Set<String> positionIds) {
        return QueryWrapperConverterPlus.of(abnGatheringJzryMapper)
                .list(AbnGatheringJzryPositionIdDTO.class, null, q -> {
                    q.eq(AbnGatheringJzry::getGatheringId, gatheringId)
                            .in(AbnGatheringJzry::getPositionId, positionIds);
                }).stream()
                .map(AbnGatheringJzryPositionIdDTO::getPositionId)
                .collect(Collectors.toList());

    }


    public List<AbnGatheringJzryQueryResultDTO> listAbnGatheringJzry(AbnGatheringJzryQueryParamDTO dto) {
        return QueryWrapperConverterPlus.of(abnGatheringJzryMapper)
                .list(AbnGatheringJzryQueryResultDTO.class, dto);
    }


    /**
     * 查询列表：分页
     *
     * @param dto  查询条件
     * @param page 分页信息
     * @return 对象列表
     */
    public QueryPageResultDTO<AbnGatheringJzryQueryResultDTO> pageAbnGatheringJzry(AbnGatheringJzryQueryParamDTO dto, PageParamDTO page) {
        return QueryWrapperConverterPlus.of(abnGatheringJzryMapper)
                .page(AbnGatheringJzryQueryResultDTO.class, dto, page);
    }

}

